<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        window.onload=function(){
            var oUl=document.getElementById('ul1');
            //IE6-8 下正常使用
            //oUl.firstChild.style.background='red'; 同childNodes一样
            //高级浏览器
           // oUl.firstElementChild.style.background='red';

            //处理兼容问题
            if(oUl.firstElementChild){
                oUl.firstElementChild.style.background='red';
            }
            else{
                oUl.firstChild.style.background='red';
            }

        };
    </script>
</head>
<body>
<ul id="ul1">
    <li>1</li>
    <li>2</li>
    <li>3</li>
</ul>
</body>
</html>